package com.htjc.integral.exchange.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.htjc.integral.common.util.StringUtil;
import com.htjc.integral.exchange.mapper.RedPacketCarouselMapper;
import com.htjc.integral.exchange.service.IRedPacketCarouselService;
import com.htjc.integral.exchange.utils.JsonUtil;
import com.htjc.integral.exchange.utils.ResultModel;
import com.htjc.integral.exchange.utils.enums.AccountReturn;
import com.htjc.integral.model.exchange.RedPacketCarousel;

import lombok.extern.slf4j.Slf4j;

@Slf4j(topic = "exchangeLogger")
@Service
public class RedPacketCarouselServiceImpl implements IRedPacketCarouselService {

	@Autowired
	private RedPacketCarouselMapper redPacketCarouselMapper;

	/**
	 * 红包轮播图接口
	 */

	@Override
	public JSONObject redPacketCarousel(JSONObject jsonObject) {

		Map<String, String> map = new HashMap<String, String>();
		map.put("channelNo", jsonObject.getString("CHANNEL_NO"));
		map.put("imgNumber", jsonObject.getString("IMG_NUMBER"));

		List<RedPacketCarousel> redPacketCarouseList = redPacketCarouselMapper.redPacketCarousel(map);
		if(redPacketCarouseList.size()<1) {
			log.error("调用红包轮播图接口失败");
			return JSONObject.parseObject(JsonUtil.bean2json(
					ResultModel.AccountReturnError(AccountReturn.REDPACKET_CAROUSEL_ERROR)));
		}
		
		List<Map<String, String>> returnList = new ArrayList<Map<String,String>>();
		
		for (RedPacketCarousel redPacketCarousel : redPacketCarouseList) {
			Map<String, String> map2 = new HashMap<>();
			map2.put("IMG_URL", redPacketCarousel.getImgUrl());
			map2.put("JUMP_URL", redPacketCarousel.getJumpUrl());
			map2.put("IMG_NAME", redPacketCarousel.getImgName());
			returnList.add(map2);
		}
		
		JSONObject successJson = new JSONObject();
		successJson.put("CHANNEL_NO", jsonObject.getString("CHANNEL_NO"));
		successJson.put("IMGLIST", returnList);
		
		return JSONObject.parseObject(JsonUtil.bean2json(ResultModel.AccountReturnSucceed(successJson)));
	}

}
